import Mock from 'mockjs'

export default {
    getMenu: config => {
        const {username, password} = JSON.parse(config.body)
        console.log(JSON.parse(config.body))
        // 先判断用户是否存在
        if (username === 'admin' || username === 'wp') {
            // 判断账号和密码是否对应
            if (username === 'admin' && password === '123456') {
                return {
                    code: 20000,
                    data: {
                        menu: [
                            {
                                icon: 's-home',
                                label: '首页',
                                path: '/home',
                                name: 'home'
                            },
                            {
                                icon: 'search',
                                label: '信息查询',
                                path: '/search',
                                name: 'search'
                            },
                            {
                                icon: 's-check',
                                label: '权限管理',
                                children: [
                                    {
                                        icon: 'setting',
                                        label: '角色管理',
                                        path: '/role',
                                        name: 'role'
                                    },
                                    {
                                        icon: 'help',
                                        label: '权限管理',
                                        path: '/access',
                                        name: 'access'
                                    },
                                    {
                                        icon: 's-operation',
                                        label: '权限分配',
                                        path: '/account',
                                        name: 'account'
                                    }
                                ]
                            },
                            {
                                icon: 'user',
                                label: '用户信息',
                                path: '/user',
                                name: 'user'
                            },
                            {
                                icon: 'collection',
                                label: '个人中心',
                                path: '/center',
                                name: 'center',
                                url: 'Center/Center'
                            },
                            {
                                icon: 's-cooperation',
                                label: '其他页面',
                                children: [
                                    {
                                        icon: 's-management',
                                        label: '页面1',
                                        path: '/pageone',
                                        name: 'pageone',
                                        url: 'Other/PageOne'
                                    },
                                    {
                                        icon: 's-ticket',
                                        label: '页面2',
                                        path: '/pagetwo',
                                        name: 'pagetwo',
                                        url: 'Other/PageTwo'
                                    }
                                ]
                            }
                        ],
                        token: Mock.Random.guid(),
                        message: '获取成功'
                    }
                }
            } else if (username === 'wp' && password === '123456') {
                return {
                    code: 20000,
                    data: {
                        menu: [
                            {
                                icon: 's-cooperation',
                                label: '其他页面',
                                children: [
                                    {
                                        icon: 's-management',
                                        label: '页面1',
                                        path: '/pageone',
                                        name: 'pageone',
                                        url: 'Other/PageOne'
                                    },
                                    {
                                        icon: 's-ticket',
                                        label: '页面2',
                                        path: '/pagetwo',
                                        name: 'pagetwo',
                                        url: 'Other/PageTwo'
                                    }
                                ]
                            }
                        ],
                        token: Mock.Random.guid(),
                        message: '获取成功'
                    }
                }
            } else {
                return {
                    code: -999,
                    data: {
                        message: '密码错误'
                    }
                }
            }
        } else {
            return {
                code: -999,
                data: {
                    message: '用户不存在'
                }
            }
        }
    }
}
